package org.xm.interceptor;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.xm.model.Result;
import org.xm.model.User;

@Slf4j
@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        // 先从请求中获取会话
        HttpSession session = request.getSession(false);
        if (session == null) {
            // 会话不存在，代表用户未登录
            log.info("用户未登录");
            return false;
        }
        log.info("当前session为:{}", session);
        return true;
    }
}
